package com.bw.module_home.adapter

import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.bawei.common.entity.BannerEntity
import com.bw.lib_image.GlideImageLoader
import com.youth.banner.adapter.BannerAdapter


/**
 * 首页banner适配器
 */

class HomeBannerAdapter(val data:List<BannerEntity>): BannerAdapter<BannerEntity, HomeBannerAdapter.BannerViewHolder>(data) {

    inner class BannerViewHolder(val imageView:ImageView):RecyclerView.ViewHolder(imageView)

    override fun onCreateHolder(parent: ViewGroup?, viewType: Int): BannerViewHolder {
        val imageView = ImageView(parent!!.context)
        //注意，必须设置为match_parent，这个是viewpager2强制要求的
        imageView.layoutParams = ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT
        )
        imageView.scaleType = ImageView.ScaleType.CENTER_CROP
        return BannerViewHolder(imageView)
    }

    override fun onBindView(
        holder: BannerViewHolder,
        data: BannerEntity,
        position: Int,
        size: Int
    ) {
        GlideImageLoader.loadResImage(holder.itemView, data.resId, holder.imageView)
    }
}